<html>
<head>
<style type="text/css">
	body	{ font-family: sans-serif; font-size: 10px; }
</style>
</head>
<body>
<?php
require ("imdb.class.php");
include 'db.inc.php';

$sql = mysql_query("SELECT * FROM m_movies LEFT JOIN m_cast ON (m_cast.movID=m_movies.mID AND cType=\"actor\") WHERE imdbID != \"\" AND mID>700 ORDER BY movID");
echo mysql_error();
$movies = array();
while($r = mysql_fetch_array($sql, MYSQL_ASSOC)){
	if(!isset($movies[$r["mID"]])){ $movies[$r["mID"]] = array("title"=>$r["title"], "imdb"=>$r["imdbID"],"count"=>0); }
	if($r["cOrdernr"] > 0){
		$movies[$r["mID"]]["count"]++;
	}
}

echo count($movies)." Movies to go...<br />";

$countdone = 0;
foreach($movies as $mID=>$mov){
	$countdone++;
	if($mov["count"] == 0){
		echo $mov["title"]." -> ".$mID." -> ".$mov["imdb"]."<br />\n";
		$ID = $mov["imdb"];
		$movie = new imdb ($ID);
		$movieid = $ID;

		$movie->setid ($movieid);
		$cols = $movie->colors ();
		$sound = $movie->sound ();
		$country = $movie->country ();

		if(!is_array($cols)){ $cols = array($cols); }
		if(!is_array($akas)){ $akas = array($akas); }
		if(!is_array($country)){ $country = array($country); }
		if(!is_array($sound)){ $sound = array($sound); }

		echo $movie->title()."<br />";

		// CAST MEMBERS
		
		$cast = $movie->cast();
		$i=0;
		if(count($cast) > 0){
			foreach($cast as $member){
				if($member["name"] != ""){
					$i++;
					mysql_query("INSERT INTO m_cast SET movID=".$mID.", cType=\"actor\", cOrdernr=\"$i\", cSubtype=\"".mysql_real_escape_string($member["role"])."\", cName=\"".mysql_real_escape_string($member["name"])."\", cIMDB=\"".$member["imdb"]."\"");
				}
			}
		}else{
			$countdone--;
		}
	}
	if(isset($_GET["loops"]) and ($countdone == $_GET["loops"])){ exit; }
}
?>
</body>
</html>